'''
Created on 2009-11-5

@author: summit
'''
import cStringIO as StringIO
import ho.pisa as pisa
import os

pisa.showLogging(True)
def HTML2PDF(html, filename, open=False):
    pdf = pisa.pisaDocument(StringIO.StringIO(html), file(filename, "wb"), path=os.getcwdu())
    
    if open and (not pdf.err):
        os.startfile(str(filename))
    
    return not pdf.err
    
if __name__ == '__main__':
    HTMLTEST = """
    <html><body> 
    <p>Hello <strong style="color: #f00;">World</strong> 
    <hr> 
    <table border="1" style="background: #eee; padding: 0.5em;"> 
    <tr> <td>Amount</td> <td>Description</td> <td>Total</td> </tr>
    <tr> <td>1</td> <td>Good weather</td> <td>0 EUR</td> </tr> 
    <tr style="font-weight: bold"> <td colspan="2" align="right">Sum</td> <td>0 EUR</td> </tr> 
    </table> </body></html> """
    HTML2PDF(file('resume2.html','rb').read(), "test.pdf", open=True)